<?php
namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\BbsCategory;
use App\Models\Cimo\Skill;
use Illuminate\Support\Facades\Input;
use App\Models\CompanyType;
use Illuminate\Support\Facades\Response;
use App\Models\CompanyJobsType;
use Illuminate\Http\Request;
use App\Models\Employ;
use App\Models\Teaches;
use App\Models\Company;
use App\Models\BbsQuestion;
use App\Models\ResumeCategory;
class CategoryController extends Controller
{
    
    
    public function __construct()
    {
		$this->middleware('auth');
    }
    
    /**
     * 根据父分类获取子分类
     */
    public function getChild()
    {
        $parent_id = Input::get('parentid',0);
        if($parent_id)
        {
            $result = Category::where('pid','=',$parent_id)->get();
            if(empty($result))
            {
                return Response::json(array('status'=>'flase','msg'=>'没有更多分类','data'=>''));            
            }
            else 
            {
                return Response::json(array('status'=>'success','msg'=>'获取分类成功','data'=>$result));
            }
        }
        return Response::json(array('status'=>'false','msg'=>'没有更多分类','data'=>''));
    }

    public function getResumeChild()
    {
        $parent_id = Input::get('parentid',0);
        if($parent_id)
        {
            $result = ResumeCategory::where('pid','=',$parent_id)->get();
            if(empty($result))
            {
                return Response::json(array('status'=>'flase','msg'=>'没有更多分类','data'=>''));
            }
            else
            {
                return Response::json(array('status'=>'success','msg'=>'获取分类成功','data'=>$result));
            }
        }
        return Response::json(array('status'=>'false','msg'=>'没有更多分类','data'=>''));
    }
    /**
     * 根据bbs_questions无限分类
     */
    public function getBbsChild(){
            $parent_id = Input::get('parentid',0);
            if($parent_id)
            {
                $result = BbsCategory::where('parent_id','=',$parent_id)->get();
                if(empty($result))
                {
                    return Response::json(array('status'=>'flase','msg'=>'没有更多分类','data'=>''));            
                }
                else 
                {
                    return Response::json(array('status'=>'success','msg'=>'获取分类成功','data'=>$result));
                }
            }
            return Response::json(array('status'=>'false','msg'=>'没有更多分类','data'=>''));
    }
    /**
     * 根据行业父分类获取子分类
     */
    public function getCompanyTtypeChild()
    {
        $parent_id = Input::get('parentid',0);
        if($parent_id)
        {
            $result = CompanyType::where('parent_id','=',$parent_id)->get();

            if(empty($result))
            {
                return Response::json(array('status'=>'flase','msg'=>'没有更多分类','data'=>''));
            }
            else
            {
                return Response::json(array('status'=>'success','msg'=>'获取分类成功','data'=>$result));
            }
        }
        return Response::json(array('status'=>'false','msg'=>'没有更多分类','data'=>''));
    }

    /**
     * 根据父分类获取子分类 职位
     */
    public function getCompanyJobTtypeChild()
    {
        $parent_id = Input::get('parentid',0);
        $childrens = CompanyJobsType::find($parent_id)->childrenCates;
        if(empty($childrens) || count($childrens) <= 0)
        {
            return Response::json(array('status'=>'flase','msg'=>'没有更多分类','data'=>''));
        }
        else
        {
            return Response::json(array('status'=>'success','msg'=>'获取分类成功','data'=>$childrens));
        }
    }

    /**
     * 根据父ID获取子级 技能
     */
    public function getSkillsChild()
    {
        $parent_id = Input::get('parentid',0);
        $childrens = Skill::find($parent_id)->children;
        if(empty($childrens) || count($childrens) <= 0)
        {
            return Response::json(array('status'=>'flase','msg'=>'没有更多','data'=>''));
        }
        else
        {
            return Response::json(array('status'=>'success','msg'=>'获取成功','data'=>$childrens));
        }
    }
    /**
     * 根据模块获取相关分类
     */
    public function getArtical(Request $req)
    {
        $module = $req->get('modules');
        $result = array();
        switch ($module)
        {
            case 'employ':
                $result = Employ::where("is_validate",'=',1)->get();
                break;
            case 'teaches':
                $result = Teaches::where("is_validate",'=',1)->get();
                break;
            case 'enterprise':
                $result = Company::all();
                break;
            case 'bbs':
                $result = BbsQuestion::all();
                break;
        }
        if(empty($result))
        {
            return Response::json(array('status'=>'faild','msg'=>'没有更多数据！','data'=>$result));
        }
        return Response::json(array('status'=>'success','msg'=>'获取信息成功！','data'=>$result));
    }
}

